************
************
*Replication Code for ``Inexperienced or Anti-Establishment? Voter Preferences for Outsider Congressional Candidates''
*Stata 16.1
*Last updated 4-6-2021
************
************


************
*Qualtrics Sample
************

*first, import data from your working directory or by calling it up with the full file path
import excel "\inexperience_replication.xlsx", sheet("Sheet1") firstrow

*example:
*import excel "C:\Users\erhan\Dropbox\Candidate Qualification Survey\inexperience_replication.xlsx", sheet("Sheet1") firstrow

*define four treatment conditions
gen exp_est = 0
replace exp_est = 1 if Q35_1 >= 0 & Q35_1 <= 100

gen inexp_est = 0
replace inexp_est = 1 if Q40_1 >= 0 & Q40_1 <= 100

gen exp_anti = 0
replace exp_anti = 1 if Q56_1 >= 0 & Q56_1 <= 100

gen inexp_anti = 0
replace inexp_anti = 1 if Q55_1 >= 0 & Q55_1 <= 100

*create treatment variables
gen experienced = 0
replace experienced = 1 if exp_est == 1 | exp_anti == 1

gen establishment = 0
replace establishment = 1 if exp_est == 1 | inexp_est == 1

*create DVs by combining outcome variables across treatment assignments
gen feeltherm = .
replace feeltherm = Q35_1 if exp_est == 1
replace feeltherm = Q40_1 if inexp_est == 1
replace feeltherm = Q56_1 if exp_anti == 1
replace feeltherm = Q55_1 if inexp_anti == 1

gen vote_raw = .
replace vote_raw = Q36 if exp_est == 1
replace vote_raw = Q41 if inexp_est == 1
replace vote_raw = Q57 if exp_anti == 1
replace vote_raw = Q53 if inexp_anti == 1

*note: next two DVs recoded with most likely to take action = 5, least likely to take action = 1
*reverse code for results
gen vote = .
replace vote = 5 if vote_raw == 1
replace vote = 4 if vote_raw == 2
replace vote = 3 if vote_raw == 3
replace vote = 2 if vote_raw == 4
replace vote = 1 if vote_raw == 5

gen donate_raw = .
replace donate_raw = Q39 if exp_est == 1
replace donate_raw = Q42 if inexp_est == 1
replace donate_raw = Q58 if exp_anti == 1
replace donate_raw = Q49 if inexp_anti == 1

*reverse code for results
gen donate = .
replace donate = 5 if donate_raw == 1
replace donate = 4 if donate_raw == 2
replace donate = 3 if donate_raw == 3
replace donate = 2 if donate_raw == 4
replace donate = 1 if donate_raw == 5

*******
*treatment effects
*******

*OLS results in Table 1, section 1 of appendix
eststo: regress feeltherm i.experienced##i.establishment
eststo: regress vote i.experienced##i.establishment
eststo: regress donate i.experienced##i.establishment
esttab using experiment.tex, b(2) star(* 0.05) se(2) ar2(2) replace
eststo clear

**********
*plot predicted values
**********

*Figure 1 of main text
gen condition = .
replace condition = 1 if exp_est == 1
replace condition = 2 if inexp_est == 1
replace condition = 3 if exp_anti == 1
replace condition = 4 if inexp_anti == 1

regress feeltherm i.condition
predict te
predict se, stdp
gen hi = te + (se*1.96)
gen lo = te - (se*1.96)
twoway rcap hi lo condition, color(black) || scatter te condition, legend(off) ytitle(Warmness toward Candidate, margin(medsmall)) yscale(range(50(5)75)) ylabel(50(5)75) ytick(50(5)75) xscale(range(0.5(1)4.5)) xlabel(1 "Exp./Est." 2 "Inexp./Est." 3 "Exp./Anti-Est." 4 "Inexp./Anti-Est.", labsize(medsmall)) xtitle("", margin(medium)) graphregion(fcolor(white)) mcolor(black)

regress vote i.condition
predict te2
predict se2, stdp
gen hi2 = te2 + (se2*1.96)
gen lo2 = te2 - (se2*1.96)
twoway rcap hi2 lo2 condition, color(black) || scatter te2 condition, legend(off) ytitle(Willingness to Vote for Candidate, margin(medsmall)) yscale(range(3(0.2)4)) ylabel(3(0.2)4) ytick(3(0.2)4) xscale(range(0.5(1)4.5)) xlabel(1 "Exp./Est." 2 "Inexp./Est." 3 "Exp./Anti-Est." 4 "Inexp./Anti-Est.", labsize(medsmall)) xtitle("", margin(medium)) graphregion(fcolor(white)) mcolor(black)

regress donate i.condition
predict te3
predict se3, stdp
gen hi3 = te3 + (se3*1.96)
gen lo3 = te3 - (se3*1.96)
twoway rcap hi3 lo3 condition, color(black) || scatter te3 condition, legend(off) ytitle(Willingness to Donate to Candidate, margin(medsmall)) yscale(range(2(0.2)3)) ylabel(2(0.2)3) ytick(2(0.2)3) xscale(range(0.5(1)4.5)) xlabel(1 "Exp./Est." 2 "Inexp./Est." 3 "Exp./Anti-Est." 4 "Inexp./Anti-Est.", labsize(medsmall)) xtitle("", margin(medium)) graphregion(fcolor(white)) mcolor(black)

****
*party subgroups
****

*Table 2, section 1 of appendix

*republicans
eststo: regress feeltherm i.experience##i.establishment if partyid == 2
eststo: regress vote i.experience##i.establishment if partyid == 2
eststo: regress donate i.experience##i.establishment if partyid == 2

*democrats
eststo: regress feeltherm i.experience##i.establishment if partyid == 1
eststo: regress vote i.experience##i.establishment if partyid == 1
eststo: regress donate i.experience##i.establishment if partyid == 1
 
*independents
eststo: regress feeltherm i.experience##i.establishment if partyid == 3 | partyid ==4
eststo: regress vote i.experience##i.establishment if partyid == 3 | partyid ==4
eststo: regress donate i.experience##i.establishment if partyid == 3 | partyid ==4

esttab using partymod.tex, b(2) star(* 0.05) se(2) ar2(2) replace
eststo clear


************
*MTurk Study 1
************

*Section 2 of appendix

*first, import data from your working directory or by calling it up with the full file path
import delimited "\MTurk_Data.csv", clear

*example:
*import delimited "C:\Users\erhan\Dropbox\Candidate Qualification Survey\MTurk\MTurk 1\MTurk_Data.csv", clear

*drop incomplete responses (n=4)
drop if progress < 95

*drop failed attention checks (n=1)
gen quality = q13
drop if q13 < 5

*rename treatment conditions
gen experience = 0
replace experience = 1 if fl_4_do == "Block1" | fl_4_do == "Block3"

gen establishment =  0
replace establishment = 1 if fl_4_do == "Block1" | fl_4_do == "Block2" 

*rename outcome variables
gen affect = q9_1

*reverse code other outcome variables
gen vote = 6 - q10
gen donate = 6 - q11
gen volunteer = 6 -q12

*main results

eststo: regress affect i.experience##i.establishment
eststo: regress vote i.experience##i.establishment
eststo: regress donate i.experience##i.establishment
eststo: regress volunteer i.experience##i.establishment
esttab using experiment.tex, b(2) star(* 0.05) se(2) ar2(2) replace
eststo clear

*descriptive statistics for sample

gen party = q1
tab party
#1 is democrat
#2 is gop
#3 is independent
#4 is other
#5 is dk

gen ideology = q2
tab ideology
mean ideology if ideology < 8
#7-point unidimensional scale
#1 is very liberal
#7 is very conservative
#8 is haven't thought much

gen gender = q14
tab gender
#1 is male
#2 is female
#3 is neither/other

gen education = .
replace education = 1 if q15 == 1
replace education = 2 if q15 == 2
replace education = 3 if q15 == 3 | q15 == 4
replace education = 4 if q15 == 5
replace education = 5 if q15 >= 6
tab education
#1 is less than hs diploma
#2 is hs diploma/ged
#3 is some college/two-year degree
#4 is four-year degree
#5 is post-graduate degree

gen age = q16_1 + 18
sum age if age >= 0

gen latinx = q17
tab latinx
#1 is yes
#2 is no

gen race = 6
replace race = 1 if q18 == "1"
replace race = 2 if q18 == "2"
replace race = 3 if q18 == "3"
replace race = 4 if q18 == "4"
replace race = 5 if q18 == "5"
tab race
#1 is white
#2 is black
#3 is american indian
#4 is asian
#5 is pacific islander
#6 is more than one/other


gen income = q19
tab income
#1 is less than $25k
#proceeds by $25k intervals to 
#5 is more than $100k
#6 is dk


************
*MTurk Study 2
************
*import data from your working directory or by calling it up with the full file path
import excel "\establishment.xlsx", sheet("Sheet0") firstrow

*example:
*import excel "C:\Users\erhan\Dropbox\Candidate Qualification Survey\MTurk\MTurk3\establishment.xlsx", sheet("Sheet0") firstrow

*drop incomplete responses (n=32)
drop if Progress < 95

*drop failed attention checks (n=2)
drop if Q7 < 5

*rename treatment conditions
*block 1 = anti-party/experienced
*block 2 = anti-party/inexperienced
*block 3 = anti-corruption/experienced
*block 4 = anti-corruption/inexperienced

gen experience = 0 
replace experience = 1 if FL_10_DO == "Block1" | FL_10_DO == "Block3"

gen corruption = 0
replace corruption = 1 if FL_10_DO == "Block3" | FL_10_DO == "Block4"

*rename/recode outcome variables
gen affect = Q25_1
gen vote = 6 - Q16
gen donate = 6 - Q17
gen volunteer = Q18

eststo: regress affect i.experience##i.corruption
eststo: regress vote i.experience##i.corruption
eststo: regress donate i.experience##i.corruption
eststo: regress volunteer i.experience##i.corruption
esttab using experiment.tex, b(2) star(* 0.05) se(2) ar2(2) replace
eststo clear


*descriptive statistics for sample

gen party = Q5
tab party
#1 is democrat
#2 is gop
#3 is independent
#4 is other
#5 is no preference
 
gen ideology = Q6
tab ideology
mean ideology if ideology <8
#7-point unidimensional scale
#1 is very liberal
#7 is very conservative
#8 is haven't thought much

gen gender = Q19
tab gender
#1 is male
#2 is female
#3 is neither/other

gen education = .
replace education = 1 if Q20 <= 4
replace education = 2 if Q20 == 5
replace education = 3 if Q20 == 6 | Q20 == 7
replace education = 4 if Q20 == 8
replace education = 5 if Q20 >= 9
tab education
#1 is less than hs diploma
#2 is hs diploma/ged
#3 is some college/two-year degree
#4 is four-year degree
#5 is post-graduate degree

gen age = Q21 + 18
sum age if age >= 0

gen latinx = Q22
tab latinx
#1 is yes
#2 is no


gen race = 6
replace race = 1 if Q23 == "1"
replace race = 2 if Q23 == "2"
replace race = 3 if Q23 == "3"
replace race = 4 if Q23 == "4"
replace race = 5 if Q23 == "5"
tab race
#1 is white
#2 is black
#3 is american indian
#4 is asian
#5 is pacific islander
#6 is more than one/other



race - q23

gen income = Q24
tab income
mean income
#1 is less than $25k
#proceeds by $25k intervals to 
#5 is more than $100k
#6 is dk
